package jzqb.controller;

import haha.life.common.CutPageBean;
import haha.life.normal.TokenUtils;
import io.swagger.annotations.Api;
import jzqb.bo.StandardBo;
import jzqb.bo.SubscriptDataBo;
import jzqb.common.Result;
import jzqb.service.SubscriptDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/subscriptData")
@Api(tags = "订阅数据")
public class SubscriptDataController {

    @Autowired
    SubscriptDataService subscriptDataService;

    /**
     * 订阅数据添加已读信息
     * @return
     */
    @PostMapping("/insertSubscriptData")
    public Result insertSubscript(@RequestBody SubscriptDataBo subscriptDataBo, HttpServletRequest request) {
        String userId = TokenUtils.getCurrentUserId(request);
        subscriptDataBo.setUserId(userId);
        SubscriptDataBo subscriptDataBos = subscriptDataService.getSubscriptDataByCondition(subscriptDataBo);
        Boolean result = false;
        if (subscriptDataBos == null) {
            result = subscriptDataService.insertSubscriptData(subscriptDataBo);
        }
        if (result) {
            return Result.succ("添加订阅数据成功");
        } else {
            return Result.succ("添加订阅数据失败");
        }
    }
    /**
     * 查询某个人在某个领域下 已读的订阅信息
     * @param subscriptDataBo
     * @param request
     * @return
     */
    @PostMapping("/getReadSubscriptData")
    public Result getReadSubscriptData(@RequestBody SubscriptDataBo subscriptDataBo, HttpServletRequest request) {
        String userId = TokenUtils.getCurrentUserId(request);
        subscriptDataBo.setUserId(userId);
        CutPageBean<SubscriptDataBo> result = subscriptDataService.getReadSubscriptData(subscriptDataBo);
        return Result.succ(result);
    }

    /**
     * 查询某个人在某个领域下 未读的订阅信息
     * @param subscriptDataBo
     * @param request
     * @return
     */
    @PostMapping("/getNoReadSubscriptData")
    public Result getNoReadSubscriptData(@RequestBody SubscriptDataBo subscriptDataBo, HttpServletRequest request) {
        String userId = TokenUtils.getCurrentUserId(request);
        subscriptDataBo.setUserId(userId);
        CutPageBean<StandardBo> result = subscriptDataService.getNoReadSubscriptData(subscriptDataBo);
        return Result.succ(result);
    }
}
